#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

class Solution {
public:
    typedef pair<int, int> PII;

    int m, n;
    int ret = 0;
    bool visited[60][60] = { false };

    int dx[4] = { 1 , -1 , 0 , 0 };
    int dy[4] = { 0 , 0 , 1 , -1 };

    int maxAreaOfIsland(vector<vector<int>>& grid)
    {
        m = grid.size();
        n = grid[0].size();

        for (int i = 0; i < m; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                if (!visited[i][j] && grid[i][j] == 1)
                {
                    ret = max(ret, bfs(grid, i, j));
                }
            }
        }

        return ret;
    }

    int bfs(vector<vector<int>>& grid, int row, int col)
    {
        queue<PII> que;
        int tmp = 0;

        que.push({ row , col });
        visited[row][col] = true;
        tmp++;

        while (!que.empty())
        {
            auto [a, b] = que.front();
            que.pop();

            for (int i = 0; i < 4; ++i)
            {
                int x = a + dx[i], y = b + dy[i];
                if (x >= 0 && x < m && y >= 0 && y < n && !visited[x][y]
                    && grid[x][y] == 1)
                {
                    que.push({ x,y });
                    visited[x][y] = true;
                    ++tmp;
                }
            }
        }

        return tmp;
    }
};

int main()
{

	return 0;
}